package com.example.learn.hwod;

import java.util.Scanner;



public class _05分批萨 {
    static int[] pizza;
    static long[][] cache;
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        pizza = new int[n];
        cache = new long[n][n];
        for (int i = 0; i <n; i++) {
            pizza[i] = sc.nextInt();
        }
        long ans=0;
        for (int i = 0; i < n; i++) {
            ans = Math.max(ans,recursive(check(i-1),check(i+1))+pizza[i]);
        }
        System.out.println(ans);


    }

    private static long recursive(int left, int right) {
        if(pizza[left]>pizza[right]){
            left = check(left-1);
        }else{
            right = check(right+1);
        }

        if(cache[left][right]>0){
            return cache[left][right];
        }
        if(left==right){
            cache[left][right]=pizza[left];
        }else{
            cache[left][right]=Math.max(recursive(check(left-1),check(right))+pizza[left],recursive(left,check(right+1))+pizza[right]);
        }
        return cache[left][right];


    }

    private static int check(int index) {
        if(index<0){
            index=pizza.length-1;
        }else if(index>=pizza.length){
            index=0;
        }
        return index;
    }
}
